import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import { isLogin } from '../utils/auth'
Vue.use(VueRouter)

let router = new VueRouter({
    mode: 'history',
    routes,
})

router.beforeEach((to, from, next) => {
    let isAuth = isLogin()
    if (to.path === '/login') {
        if (isAuth) {
            next('/')
        } else {
            next()
        }
    } else {
        if (isAuth) {
            next()
        } else {
            next('/login')
        }
    }
})

export default router